import { useState } from 'react';

export const usePatchElement = () => {
  const [elements, setElements] = useState<React.ReactElement[]>([]);

  const patchElement = (element: React.ReactElement) => {
    setElements((prev) => [...prev, element]);

    return () => {
      setElements((prev) => prev.filter((e) => e !== element));
    };
  };

  return [elements, patchElement] as const;
};
